package com.abel.bigwater.wflow

import com.drew.imaging.ImageMetadataReader
import org.junit.Test
import org.slf4j.LoggerFactory
import java.io.File

class ToolTest {
    @Test
    fun testToDouble() {
        println("1000".toDoubleOrNull())
        println("1,000".toDoubleOrNull())
        println("1,000".replace(",", "").toDoubleOrNull())
    }

    /**
     * GPS ~ GPS Latitude Ref: N
     * GPS ~ GPS Latitude: 39° 55' 27.65"
     * GPS ~ GPS Longitude Ref: E
     * GPS ~ GPS Longitude: 116° 24' 7.06"
     * GPS ~ GPS Altitude Ref: Sea level
     * GPS ~ GPS Altitude: 49.64 metres
     * GPS ~ GPS Time-Stamp: 03:52:10.000 UTC
     * GPS ~ GPS Speed Ref: km/h
     * GPS ~ GPS Speed: 0 km/h
     * GPS ~ GPS Img Direction Ref: True direction
     * GPS ~ GPS Img Direction: 88.09 degrees
     * GPS ~ GPS Dest Bearing Ref: True direction
     * GPS ~ GPS Dest Bearing: 88.09 degrees
     * GPS ~ GPS Date Stamp: 2019:02:10
     * GPS ~ GPS H Positioning Error: 50 metres
     */
    @Test
    fun testMetadata() {
        var md = ImageMetadataReader.readMetadata(File("E:\\workspace44\\bw-wflow\\ticket-flow.jpg"))
        md.directories.forEach {
            it.tags.forEach { tag -> lgr.info("${it.name} ~ ${tag.tagName}: ${tag.description}") }
        }

        val file2 = "E:\\workspace44\\bw-wflow\\gps-test.jpg"
        lgr.info("""
            |===========================
            |${file2}
            |===========================
        """.trimMargin())
        md = ImageMetadataReader.readMetadata(File(file2))
        md.directories.forEach {
            it.tags.forEach { tag -> lgr.info("${it.name} ~ ${tag.tagName}: ${tag.description}") }
        }
    }

    @Test
    fun testDegree() {
        val dg = LocHelper.changeToDegree("N39° 55' 27.65\"")
        val dg2 = LocHelper.changeToDegree("E116° 24' 7.06\"")
        lgr.info("north : $dg; east : $dg2")

        val dms = LocHelper.changeToDms(39.9243472222)
        val dms2 = LocHelper.changeToDms(116.4019611111)
        lgr.info("N $dms; E $dms2")
    }

    @Test
    fun testPhotoLoc() {
        val lt = LocHelper.parseLoc(File("E:\\workspace44\\bw-wflow\\gps-test.jpg").inputStream(), lgr)
        lgr.info(lt.toString())

        val lt2 = LocHelper.parseLoc(File("E:\\workspace44\\bw-wflow\\ticket-flow.jpg").inputStream(), lgr)
        lgr.info(lt2.toString())
    }

    companion object {
        private val lgr = LoggerFactory.getLogger(ToolTest::class.java)
    }
}